//
// Created by hps on 24-4-2.
//
#include "../src/widgets/Config.h"
#include "../src/widgets/FileManager.h"
#include <QtWidgets/QApplication>
#include <QtCore/qdir.h>
#include <iostream>

void test_TreeItem(int argc, char *argvs[]) {
    QApplication app(argc, argvs);
    hps::FileManager fileManager;
    fileManager . setHeaderHidden(true);
    QTreeWidgetItem *item1 = new QTreeWidgetItem(&fileManager);
    item1 -> setText(0, "item1");
    QTreeWidgetItem *item2 = new QTreeWidgetItem(item1);
    item2 -> setText(0, "item2");
    QTreeWidgetItem *item3 = new QTreeWidgetItem(item2);
    item3 -> setText(0, "item3.txt");
    item3 -> setIcon(0, QIcon("/home/hps/hps/Markdown-cpp/src/data/icon/file.svg"));
    fileManager . show();
    app . exec();
}

void test_noteBookList() {
    auto p = CONFIG() -> getNoteBookCfg();
    std::cout << p . DataBaseName << std::endl;
    for (auto &s: p . NoteBookMap) {
        std::cout << s . first << ", " << s . second << std::endl;
    }
}

void populateTreeWidget(const QString &path, QTreeWidgetItem *parentItem) {
    QDir dir(path);
    QFileInfoList fileInfoList = dir . entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);

    for (const QFileInfo &fileInfo: fileInfoList) {
        QTreeWidgetItem *item = new QTreeWidgetItem(parentItem);
        item -> setText(0, fileInfo . fileName());

        if (fileInfo . isDir()) {
            populateTreeWidget(fileInfo . filePath(), item); // 递归添加子目录
        }
    }
}

void test_FIleMgr(int argc, char *argv[]) {
    QApplication a(argc, argv);

    QTreeWidget treeWidget;
    populateTreeWidget("/home/hps/hps/Markdown-cpp/tests/TestData/huangpeishen", treeWidget . invisibleRootItem());

    treeWidget . show();

     a . exec();
}


int main(int argc, char *argvs[]) {
    test_FIleMgr(argc, argvs);
//    test_noteBookList();
    return 0;
}